package com.ui.zhixiao.controller;

import com.ui.zhixiao.common.R;
import com.ui.zhixiao.domain.Liketable;
import com.ui.zhixiao.mapper.LiketableMapper;
import com.ui.zhixiao.service.LiketableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/liketable")
public class LiketableController {
    @Autowired
    private LiketableService liketableService;

    @GetMapping("/{id}")
    public R<Liketable> getById(@PathVariable Long id){
        Liketable liketable = liketableService.getById(id);
        if(liketable !=null){
            return R.success(liketable);
        }
        return R.error("查询失败");
    }
    @PostMapping("/likestatus/{id}")
    public R<String> updateLikeStatus(@PathVariable Long id){
        Liketable liketable = liketableService.getById(id);
        Integer likeStatus = liketable.getLikeStatus();
        if(likeStatus == 1){
            liketable.setLikeStatus(0);
        }else{
            liketable.setLikeStatus(1);
        }


        liketableService.updateById(liketable);

        return R.success(liketable.getLikeStatus().toString());
    }

    @PostMapping("/collectstatus/{id}")
    public R<String> updateCollectStatus(@PathVariable Long id){
        Liketable liketable = liketableService.getById(id);
        Integer likeStatus = liketable.getCollectStatus();
        if(likeStatus == 1){
            liketable.setCollectStatus(0);
        }else{
            liketable.setCollectStatus(1);
        }
        liketableService.updateById(liketable);

        return R.success(liketable.getCollectStatus().toString());
    }

}

